home *** CD-ROM | disk | FTP | other *** search
/ Cracking 1 / Cracking I..iso / Tools / Ostatní / aPLib v0.26b / src / nasm / depackf.nas < prev    next >
Encoding:
Text File  |  2001-12-15  |  2.2 KB  |  134 lines

  1. ;;
  2. ;; aPLib compression library  -  the smaller the better :)
  3. ;;
  4. ;; NASM fast assembler depacker
  5. ;;
  6. ;; Copyright (c) 1998-2000 by Joergen Ibsen / Jibz
  7. ;; All Rights Reserved
  8. ;;
  9. ;; -> NASM by Archee/CoNTRACT (soltesz@hotmail.com)
  10. ;;
  11.  
  12. section .text use32
  13.  
  14. global _aP_depack_asm_fast
  15.  
  16. %macro getbitM 0
  17.     add    dl, dl
  18.     jnz    %%stillbitsleft
  19.     mov    dl, [esi]
  20.     inc    esi
  21.     adc    dl, dl
  22. %%stillbitsleft:
  23. %endmacro
  24.  
  25. %macro domatchM 1
  26.     push   esi
  27.     mov    esi, edi
  28.     sub    esi, %1
  29.     rep    movsb
  30.     pop    esi
  31. %endmacro
  32.  
  33. %macro getgammaM 1
  34.     mov    %1, 1
  35. %%getmore:
  36.     getbitM
  37.     adc    %1, %1
  38.     getbitM
  39.     jc     %%getmore
  40. %endmacro
  41.  
  42. _aP_depack_asm_fast:
  43.     pushad
  44.  
  45.     mov    esi, [esp + 36]    ; C calling convention
  46.     mov    edi, [esp + 40]
  47.  
  48.     cld
  49.     mov    dl, 80h
  50.  
  51. literal:
  52.     mov     al, [esi]
  53.     inc     esi
  54.     mov     [edi], al
  55.     inc     edi
  56.  
  57. nexttag:
  58.     getbitM
  59.     jnc    literal
  60.  
  61.     getbitM
  62.     jnc    codepair
  63.  
  64.     xor    eax, eax
  65.     getbitM
  66.     jnc    near shortmatch
  67.  
  68.     getbitM
  69.     adc    eax, eax
  70.     getbitM
  71.     adc    eax, eax
  72.     getbitM
  73.     adc    eax, eax
  74.     getbitM
  75.     adc    eax, eax
  76.     jz     thewrite
  77.     push   edi
  78.     sub    edi, eax
  79.     mov    al, [edi]
  80.     pop    edi
  81. thewrite:
  82.     mov    [edi], al
  83.     inc    edi
  84.     jmp    short nexttag
  85.  
  86. codepair:
  87.     getgammaM eax
  88.     sub    eax, 2
  89.     jnz    normalcodepair
  90.     getgammaM ecx
  91.     domatchM ebp
  92.     jmp    nexttag
  93.  
  94. normalcodepair:
  95.     dec    eax
  96.     shl    eax, 8
  97.     mov    al, [esi]
  98.     inc    esi
  99.     mov    ebp, eax
  100.     getgammaM ecx
  101.     cmp    eax, 32000
  102.     jae    do_add_2
  103.     cmp    eax, 1280
  104.     jb     not_gt_1280
  105.     inc    ecx
  106.     domatchM eax
  107.     jmp    nexttag
  108. not_gt_1280:
  109.     cmp    eax, BYTE 7fh
  110.     ja     dont_add_2
  111. do_add_2:
  112.     add    ecx, 2
  113. dont_add_2:
  114.     domatchM eax
  115.     jmp    nexttag
  116.  
  117. shortmatch:
  118.     mov    al, [esi]
  119.     inc    esi
  120.     xor    ecx, ecx
  121.     db     0c0h, 0e8h, 001h
  122.     jz     donedepacking
  123.     adc    ecx, BYTE 2
  124.     mov    ebp, eax
  125.     domatchM eax
  126.     jmp    nexttag
  127.  
  128. donedepacking:
  129.     sub    edi, [esp + 40]
  130.     mov    [esp + 28], edi    ; return unpacked length in eax
  131.  
  132.     popad
  133.     ret
  134.